package com.wilmer.knowledges.controller;

import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.core.page.TableDataInfo;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.knowledges.domain.YwKnowledgeType;
import com.wilmer.knowledges.service.IYwKnowledgeTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 知识库类型Controller
 * 
 * @author hans
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/knowledgesType/knowledgesType")
public class YwKnowledgeTypeController extends BaseController
{
    @Autowired
    private IYwKnowledgeTypeService ywKnowledgeTypeService;

    /**
     * 查询知识库类型列表
     */
    @PreAuthorize("@ss.hasPermi('knowledgesType:knowledgesType:list')")
    @GetMapping("/list")
    public TableDataInfo list(YwKnowledgeType ywKnowledgeType)
    {
        startPage();
        List<YwKnowledgeType> list = ywKnowledgeTypeService.selectYwKnowledgeTypeList(ywKnowledgeType);
        return getDataTable(list);
    }

    /**
     * 导出知识库类型列表
     */
    @PreAuthorize("@ss.hasPermi('knowledgesType:knowledgesType:export')")
    @Log(title = "知识库类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwKnowledgeType ywKnowledgeType)
    {
        List<YwKnowledgeType> list = ywKnowledgeTypeService.selectYwKnowledgeTypeList(ywKnowledgeType);
        ExcelUtil<YwKnowledgeType> util = new ExcelUtil<YwKnowledgeType>(YwKnowledgeType.class);
        util.exportExcel(response, list, "知识库类型数据");
    }

    /**
     * 获取知识库类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('knowledgesType:knowledgesType:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(ywKnowledgeTypeService.selectYwKnowledgeTypeByTypeId(typeId));
    }

    /**
     * 新增知识库类型
     */
    @PreAuthorize("@ss.hasPermi('knowledgesType:knowledgesType:add')")
    @Log(title = "知识库类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwKnowledgeType ywKnowledgeType)
    {
        return toAjax(ywKnowledgeTypeService.insertYwKnowledgeType(ywKnowledgeType));
    }

    /**
     * 修改知识库类型
     */
    @PreAuthorize("@ss.hasPermi('knowledgesType:knowledgesType:edit')")
    @Log(title = "知识库类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwKnowledgeType ywKnowledgeType)
    {
        return toAjax(ywKnowledgeTypeService.updateYwKnowledgeType(ywKnowledgeType));
    }

    /**
     * 删除知识库类型
     */
    @PreAuthorize("@ss.hasPermi('knowledgesType:knowledgesType:remove')")
    @Log(title = "知识库类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(ywKnowledgeTypeService.deleteYwKnowledgeTypeByTypeIds(typeIds));
    }
}
